package com.fau.hm.entity;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

import org.hibernate.Hibernate;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;
import org.json.simple.JSONAware;
import org.json.simple.JSONObject;

import com.fau.hm.util.SystemConfig;

/**
 * @desc 员工基本工资表
 * @author liy
 * @datetime 2014年11月17日,下午2:10:42
 */
@Entity
@Table(name = "medical_staff_basic")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class MedicalStaffBasic implements Serializable, JSONAware{

	private static final long serialVersionUID = 8372556321881395006L;
	private String id;
	
	@NotNull(message = "员工id不能为空！")
	private MedicalAdmin user;				// 员工
	
	private String deptType;				// 部门
	private String isLeader;				// 组长、组员
	
	@NotNull(message = "基本工资id不能为空！")
	private BigDecimal basic;				// 基本工资
	private Date createTime = new Date();	// 创建时间
	private Date updateTime = new Date();	// 更新时间
	
	private String uid;						// 员工id
	private String dept;					// 部门id
	private String position;				// 职位id
	private String name;					// 员工姓名
	private String platformId;				// 中心id
	
	private String typeName;				// 字典表类型
	
	@Id
	@GenericGenerator(name = "generator", strategy = "uuid.hex")
	@GeneratedValue(generator = "generator")
	@Column(name = "id", length = 32)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@OneToOne
	@JoinColumn(name = "uid")
	public MedicalAdmin getUser() {
		return user;
	}

	public void setUser(MedicalAdmin user) {
		this.user = user;
	}

	@Column(name = "dept_type", length = 20)
	public String getDeptType() {
		return deptType;
	}

	public void setDeptType(String deptType) {
		this.deptType = deptType;
	}

	@Column(name = "is_leader", length = 5)
	public String getIsLeader() {
		return isLeader;
	}

	public void setIsLeader(String isLeader) {
		this.isLeader = isLeader;
	}

	@Column(name = "basic", length = 9, precision = 2)
	public BigDecimal getBasic() {
		return basic;
	}

	public void setBasic(BigDecimal basic) {
		this.basic = basic;
	}
	
	@Transient
	public String getDept() {
		return dept;
	}

	public void setDept(String dept) {
		this.dept = dept;
	}

	@Transient
	public String getPosition() {
		return position;
	}

	public void setPosition(String position) {
		this.position = position;
	}
	
	@Transient
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	@Transient
	public String getPlatformId() {
		return platformId;
	}

	public void setPlatformId(String platformId) {
		this.platformId = platformId;
	}

	@Transient
	public String getTypeName() {
		return typeName;
	}

	public void setTypeName(String typeName) {
		this.typeName = typeName;
	}

	@Transient
	public String getUid() {
		return uid;
	}

	public void setUid(String uid) {
		this.uid = uid;
	}

	@Column(name = "create_time")
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Column(name = "update_time")
	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	@SuppressWarnings("unchecked")
	@Override
	public String toJSONString() {
		JSONObject object = new JSONObject();
		object.put("id", id);
		object.put("name", user.getName());
		object.put("uid", user.getId());
		object.put("deptType", deptType);
		object.put("isLeader", isLeader);
		object.put("dept", dept);
		if(Hibernate.isInitialized(user.getGroup())) {
			object.put("platformName", user.getGroup().getName());
			object.put("groupName", user.getGroup().getName());
		}
		object.put("platformId", platformId);
		if(SystemConfig.GROUP_LEADER.equals(user.getIsLeader())) {
			object.put("positionName", "组长");
		} else if(SystemConfig.GROUP_EMPLOYEE.equals(user.getIsLeader())) {
			object.put("positionName", "组员");
		}
		object.put("basic", basic);
		return object.toString();
	}

}
